const BaseIpcHandler = require('../BaseIpcHandler');
class GetModelConfigsHandler extends BaseIpcHandler {
    async handle(event, params) {
        // 解析参数
        // console.log('>> GetModelConfigsHandler params = ', params);
        const { model_id } = params;

        // 业务逻辑
        let result = null;
        try {
            let model_clouds = await this.app.models_cloud_db.models_cloud.GetCloudModels(model_id);
            let model_cloud = model_clouds[0];
            // console.log(model_cloud);

            // 获取模型对应的jsproxy路径
            let jsproxy_path = model_cloud.script_jsproxy;
            const handlerClass = require(jsproxy_path);
            const jsproxy = new handlerClass();
            let data = await jsproxy.loadConfigList();
            result = { code: 0, msg: data };
        } catch (err) {
            console.error(`Error get model config list, error = : `, err);
            result = { code: -1, msg: err.message };
        }

        // 返回结果
        if (event.from === 'localserver') {
            event.resp.send(result);
        } else {
            return result;
        }
    }
}

module.exports = GetModelConfigsHandler;
